#include "StdAfx.h"
#include "ChatTabCtrl.h"

BEGIN_MESSAGE_MAP(CChatTabCtrl, CTabCtrl)
	//{{AFX_MSG_MAP(CXTabCtrl)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CChatTabCtrl::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	m_bShowColor = !m_bShowColor;
	for(int i = 0; i < m_vcBlankTabs.size(); i++) {
		
		CRect rectItem;
		GetItemRect(m_vcBlankTabs[i], rectItem);
		InvalidateRect(&rectItem);
		
	}

	CTabCtrl::OnTimer(nIDEvent);
}

void CChatTabCtrl::InsertBlankItem(UINT uId)
{
	std::vector<char>::iterator it;
	it = find(m_vcBlankTabs.begin(), m_vcBlankTabs.end(), uId);
	if(it == m_vcBlankTabs.end()) {
		m_vcBlankTabs.push_back(uId);
	}
	
	return ;
}
int CChatTabCtrl::GetBlankItemCount()
{
	return m_vcBlankTabs.size();
}
void CChatTabCtrl::DeleteBlankItem(UINT uId)
{
	std::vector<char>::iterator it;

	it = find(m_vcBlankTabs.begin(), m_vcBlankTabs.end(), uId);
	if(it != m_vcBlankTabs.end()) {
		m_vcBlankTabs.erase(it);
		CRect rectItem;
		GetItemRect(uId, rectItem);
		rectItem.bottom += 5;
		rectItem.left -= 2;
		rectItem.right += 2;
		InvalidateRect(&rectItem);
	}
	return ;
}


void CChatTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	
	

	TC_ITEM tci;
	CDC* pDC = CDC::FromHandle(lpDIS->hDC);
	CRect rect(lpDIS->rcItem);
	char szTabText[256];
	memset(szTabText,'\0',sizeof(szTabText));

	tci.mask = TCIF_TEXT;
	tci.pszText = szTabText;
	tci.cchTextMax = sizeof(szTabText) -1;
	GetItem(lpDIS->itemID, &tci);
	ITBlankTabs it;
	it = find(m_vcBlankTabs.begin(), m_vcBlankTabs.end(), lpDIS->itemID);
	if(it != m_vcBlankTabs.end()) {
		UINT        bkColor;
		if(m_bShowColor) {
			bkColor = RGB(255,0,0);
			pDC->SetBkMode(OPAQUE);
			CBrush m_brRed;
			m_brRed.CreateSolidBrush(RGB(255,0,0));
			pDC->FillRect(&lpDIS->rcItem, &m_brRed);
			pDC->SetBkColor(bkColor);
			pDC->TextOut(rect.left+5, rect.top+5, tci.pszText);
		} else {
			pDC->SetBkMode(TRANSPARENT);
			pDC->TextOut(rect.left+5, rect.top+5, tci.pszText);
		}
		
		return ;
	} 


	if (lpDIS->itemAction & ODA_DRAWENTIRE)
	{
		pDC->TextOut(rect.left+5, rect.top+5, tci.pszText);
	}

	if ((lpDIS->itemState & ODS_SELECTED) && (lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
	{
		//Make the color of text of the selected tab to be BLUE.
		pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0,0,255));
		pDC->TextOut(rect.left+5, rect.top+5, tci.pszText);
	}


}
